package com.coursehub.exercise.repository;

import com.coursehub.exercise.entity.StudentExercise;
import com.coursehub.exercise.entity.StudentExerciseId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentExerciseRepository extends JpaRepository<StudentExercise, StudentExerciseId> {

    List<StudentExercise> findByIdExerciseId(String exerciseId);

    List<StudentExercise> findByIdUserId(String userId);

    @Query("SELECT se FROM StudentExercise se WHERE se.id.exerciseId = :exerciseId AND se.state = com.coursehub.exercise.entity.StudentExercise$ExerciseState.submitted")
    List<StudentExercise> findSubmittedByExerciseId(@Param("exerciseId") String exerciseId);
}


